﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace XoniXNA
{
    public enum Direction
	{
	    Up,
        Left,
        Right,
        Down
	}

    public class Player : DrawableGameComponent
    {
        public PlayerDescription Description { get; set; }
        Texture2D playerTexture;

        public Texture2D PlayerTexture
        {
            get { return playerTexture; }
            set { playerTexture = value; }
        }
        Texture2D pathTexture;

        public Texture2D PathTexture
        {
            get { return pathTexture; }
            set { pathTexture = value; }
        }
        public Player(Game game, PlayerDescription description):base(game)
        {
            Description = description;
        }

        public override void Draw(GameTime gameTime)
        {
            SpriteBatch sb = ((XonixGame)this.Game).SpriteBatch;
            sb.Begin();
            sb.Draw(playerTexture, Description.Location, Color.White);
            sb.End();
            base.Draw(gameTime);
        }

        public void Move(Direction dir)
        {
            int width = ((XonixGame)Game).BoardWidth * Constants.CELL_SIZE;
            int height = ((XonixGame)Game).BoardHeight * Constants.CELL_SIZE;
            Vector2 padding = ((XonixGame)Game).BoardPadding;

            switch (dir)
            {
                case Direction.Up:
                    if (Description.Location.Y - 1 >= Constants.CELL_SIZE + padding.Y)
                    {
                        Description.SetLocationY(Description.Location.Y - 1);
                    }
                    break;
                case Direction.Left:
                    if (Description.Location.X - 1 >= padding.X)
                    {
                        Description.SetLocationX(Description.Location.X - 1);
                    }
                    break;
                case Direction.Right:
                    if (Description.Location.X + 1 <= padding.X + width - Constants.CELL_SIZE)
                    {
                        Description.SetLocationX(Description.Location.X + 1);
                    }
                    break;
                case Direction.Down:
                    if (Description.Location.Y + 1 <= height - Constants.CELL_SIZE + padding.Y)
                    {
                        Description.SetLocationY(Description.Location.Y + 1);
                    }
                    break;
                default:
                    break;
            }
        }

        
    }


    //TODO: add velocity info
    public class PlayerDescription
    {
        public string Name { get; set; }
        public int Score { get; set; }
        Vector2 location;

        public Vector2 Location
        {
            get { return location; }
            set { location = value; }
        }


        public PlayerDescription (string name, int score, Vector2 startLocation)
	    {
            location = startLocation;
            Name = name;
            Score = score;
	    }



        internal void SetLocationY(float p)
        {
            location.Y = p;
        }

        internal void SetLocationX(float p)
        {
            location.X = p;
        }
    }
}
